﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zen4SyncPOCO.Enum.Admin;
using Zen4SyncPOCO.Enum.MergeSync;
using Zen4SyncOrchestrator.Exceptions;
using Zen4SyncPOCO.POCO.Enum.Scenario;

namespace Zen4SyncOrchestrator
{
    /// <summary>
    /// Provides methods to get the Enum equivalent of a Guid.
    /// This conversion applies to referential data such as Network Type, Validate Type etc.
    /// </summary>
    internal static class GuidToEnum
    {
        /// <summary>
        /// Gets the Enum equivalent of a SqlValueType extracted from database.
        /// </summary>
        internal static SqlValueTypeEnum SqlValueType(Guid sqlValueTypeGuid)
        {
            if (sqlValueTypeGuid == Zen4SyncModel.Referential.Guid.SqlValueType.Bit)
            {
                return SqlValueTypeEnum.Bit;
            }
            else if (sqlValueTypeGuid == Zen4SyncModel.Referential.Guid.SqlValueType.DateTime)
            {
                return SqlValueTypeEnum.DateTime;
            }
            else if (sqlValueTypeGuid == Zen4SyncModel.Referential.Guid.SqlValueType.Int)
            {
                return SqlValueTypeEnum.Int;
            }
            else if (sqlValueTypeGuid == Zen4SyncModel.Referential.Guid.SqlValueType.NVarchar)
            {
                return SqlValueTypeEnum.Nvarchar;
            }
            else if (sqlValueTypeGuid == Zen4SyncModel.Referential.Guid.SqlValueType.Varchar)
            {
                return SqlValueTypeEnum.Varchar;
            }
            else if (sqlValueTypeGuid == Zen4SyncModel.Referential.Guid.SqlValueType.SmallInt)
            {
                return SqlValueTypeEnum.SmallInt;
            }
            else if (sqlValueTypeGuid == Zen4SyncModel.Referential.Guid.SqlValueType.UniqueIdentifier)
            {
                return SqlValueTypeEnum.UniqueIdentifier;
            }
            else if (sqlValueTypeGuid == Zen4SyncModel.Referential.Guid.SqlValueType.Xml)
            {
                return SqlValueTypeEnum.Xml;
            }
            else
            {
                throw new Zen4SyncOrchestratorException(Zen4SyncOrchestratorException.Messages.UNKNOWN_ITEM_BY_ID, new string[] { "sqlValueTypeId", sqlValueTypeGuid.ToString() });
            }
        }

        /// <summary>
        /// Gets the Enum equivalent of a ValidateType extracted from database.
        /// </summary>
        internal static ValidateTypeEnum ValidateType(Guid validateTypeId)
        {
            if (validateTypeId == Zen4SyncModel.Referential.Guid.ValidateType.NoValidation)
            {
                return ValidateTypeEnum.NoValidation;
            }
            else if (validateTypeId == Zen4SyncModel.Referential.Guid.ValidateType.RowCountOnly)
            {
                return ValidateTypeEnum.RowCountOnly;
            }
            else
            {
                throw new Zen4SyncOrchestratorException(Zen4SyncOrchestratorException.Messages.UNKNOWN_ITEM_BY_ID, new string[] { "validateTypeId", validateTypeId.ToString() });
            }
        }

        /// <summary>
        /// Gets the Enum equivalent of a NetworkType extracted from database.
        /// </summary>
        internal static NetworkTypeEnum NetworkType(Guid networkTypeId)
        {
            if (networkTypeId == Zen4SyncModel.Referential.Guid.NetworkType.DefaultNetwork)
            {
                return NetworkTypeEnum.DefaultNetwork;
            }
            else if (networkTypeId == Zen4SyncModel.Referential.Guid.NetworkType.MultiProtocol)
            {
                return NetworkTypeEnum.MultiProtocol;
            }
            else if (networkTypeId == Zen4SyncModel.Referential.Guid.NetworkType.TcpIpSockets)
            {
                return NetworkTypeEnum.TcpIpSockets;
            }
            else
            {
                throw new Zen4SyncOrchestratorException(Zen4SyncOrchestratorException.Messages.UNKNOWN_ITEM_BY_ID, new string[] { "networkTypeId", networkTypeId.ToString() });
            }
        }

        /// <summary>
        /// Gets the Enum equivalent of a SecurityType extracted from database.
        /// </summary>
        internal static SecurityTypeEnum SecurityType(Guid securityTypeId)
        {
            if (securityTypeId == Zen4SyncModel.Referential.Guid.SecurityType.DBAuthentication)
            {
                return SecurityTypeEnum.DBAuthentication;
            }
            else if (securityTypeId == Zen4SyncModel.Referential.Guid.SecurityType.NTAuthentication)
            {
                return SecurityTypeEnum.NTAuthentication;
            }
            else
            {
                throw new Zen4SyncOrchestratorException(Zen4SyncOrchestratorException.Messages.UNKNOWN_ITEM_BY_ID, new string[] { "securityTypeId", securityTypeId.ToString() });
            }
        }

        /// <summary>
        /// Gets the Enum equivalent of an ExchangeType extracted from database.
        /// </summary>
        internal static ExchangeTypeEnum ExchangeType(Guid exchangeTypeId)
        {
            if (exchangeTypeId == Zen4SyncModel.Referential.Guid.ExchangeType.BiDirectional)
            {
                return ExchangeTypeEnum.BiDirectional;
            }
            else if (exchangeTypeId == Zen4SyncModel.Referential.Guid.ExchangeType.None)
            {
                return ExchangeTypeEnum.None;
            }
            else if (exchangeTypeId == Zen4SyncModel.Referential.Guid.ExchangeType.Upload)
            {
                return ExchangeTypeEnum.Upload;
            }
            else
            {
                throw new Zen4SyncOrchestratorException(Zen4SyncOrchestratorException.Messages.UNKNOWN_ITEM_BY_ID, new string[] { "exchangeTypeId", exchangeTypeId.ToString() });
            }
        }

        /// <summary>
        /// Gets the Enum equivalent of a SnapshotTransferType extracted from database.
        /// </summary>
        internal static SnapshotTransfertTypeEnum SnapshotTransferType(Guid snapshotTransferTypeId)
        {
            if (snapshotTransferTypeId == Zen4SyncModel.Referential.Guid.SnapshotTransferType.FTP)
            {
                return SnapshotTransfertTypeEnum.FTP;
            }
            else if (snapshotTransferTypeId == Zen4SyncModel.Referential.Guid.SnapshotTransferType.UNC)
            {
                return SnapshotTransfertTypeEnum.UNC;
            }
            else
            {
                throw new Zen4SyncOrchestratorException(Zen4SyncOrchestratorException.Messages.UNKNOWN_ITEM_BY_ID, new string[] { "snapshotTransferTypeId", snapshotTransferTypeId.ToString() });
            }
        }

        /// <summary>
        /// Gets the Enum equivalent of a ActivityType extracted from database.
        /// </summary>
        internal static ActivityTypeEnum ActivityType(Guid activityTypeId)
        {
            if (activityTypeId == Zen4SyncModel.Referential.Guid.ActivityType.SyncSession)
            {
                return ActivityTypeEnum.SyncSession;
            }
            else if (activityTypeId == Zen4SyncModel.Referential.Guid.ActivityType.SqlServerExecution)
            {
                return ActivityTypeEnum.SqlServerExecution;
            }
            else if (activityTypeId == Zen4SyncModel.Referential.Guid.ActivityType.SqlServerCheckData)
            {
                return ActivityTypeEnum.SqlServerCheckData;
            }
            else if (activityTypeId == Zen4SyncModel.Referential.Guid.ActivityType.SqlCEExecution)
            {
                return ActivityTypeEnum.SqlCeExecution;
            }
            else if (activityTypeId == Zen4SyncModel.Referential.Guid.ActivityType.SqlCECheckData)
            {
                return ActivityTypeEnum.SqlCeCheckData;
            }

            else if (activityTypeId == Zen4SyncModel.Referential.Guid.ActivityType.SqlCEBackup)
            {
                return ActivityTypeEnum.SqlCeBackup;
            }

            else if (activityTypeId == Zen4SyncModel.Referential.Guid.ActivityType.MefExecution)
            {
                return ActivityTypeEnum.MefExecution;
            }
            else
            {
                throw new Zen4SyncOrchestratorException(Zen4SyncOrchestratorException.Messages.UNKNOWN_ITEM_BY_ID, new string[] { "activityTypeId", activityTypeId.ToString() });
            }
        }
    }
}
